<?php 
		include 'db.php';
		$href="http://" .$_SERVER['HTTP_HOST']. "/group4/nguyenvanthien/";
		// Create table 
		/*
		$sql = "CREATE TABLE dhv_nguyenvanthien_user
		( 
		uid INT(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
		username VARCHAR(255), 
		password VARCHAR(255) ,
		email VARCHAR(255) 
		)"; 
		$query_create=mysql_query($sql,$conection); 
		if($query_create){
			echo "tao table thanh cong";
		}
		*/
		if(isset($_POST['ok'])){
			$name=$pass="";
			$mgs="";
			$name=mysql_real_escape_string($_POST['username']);
			$pass=md5(mysql_real_escape_string($_POST['password']));
			if($name && $pass){
				$sql="SELECT * FROM dhv_nguyenvanthien_user WHERE username='".$name."' AND password='".$pass."'";
				$query=mysql_query($sql);
				if(mysql_num_rows($query)==0){
					$mgs="<p>Bạn chưa đăng ký</p>";
				}
				else{
					while($row=mysql_fetch_array($query)){
						setcookie("username_thien",$name,time()+3600*24*30,'/') or die('unable to create cookie');
						setcookie("email_thien",$row['email'],time()+3600*24*30,'/') or die('unable to create cookie');
						header('location:issue6.php');
						exit();
						
					}
					
				}
			}
		}//end if
		if(isset($_COOKIE['username_thien'])){
			header('location:issue6.php');
			exit();
		}
	?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title></title>
	<link type="text/css" href="css/style.css" rel="stylesheet" />
	<script type="text/javascript" src="js/jquery-1.10.2.js" ></script>
	<script type="text/javascript" src="js/jquery.validate.min.js" ></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$("#input_form").validate(); 
		})
	</script>
</head>
<body>
	<div class="login register">	
		<form action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>' method='post' id='input_form'>
			<fieldset>
				<legend>Form Login</legend>	
				<label>Username:</label> <br>
				<input type='text' name='username' size='25' class="required" /><br />
				<label>Password:</label> <br>
				<input type='password' name='password' size='25' class="required" /><br />
				<input type='submit' name='ok' value='Login' />
				<a target="_blank" href="<?php echo $href ."issue7-regisster.php"; ?>">Register</a>
				<?php 
					if(isset($mgs)) echo $mgs;
				?>
			</fieldset>
		</form>
	</div>
</body>
</html>